<?php
namespace app\attachment\loglic;

class Datas
{
    //批量写入插件初始配置
    public function insertConfig()
    {
        return model('common/Config','loglic')->install([
            'attachment' => 1,
        ],'common');
    }
    
    //批量写入插件动态字段
    public function insertField()
    {
        return model('common/Field','loglic')->install([
            [
                'op_name'     => 'attachment',
                'op_value'    => json_encode([
                    'type'      => 'select',
                    'value'     => 1,
                    'option'    => [0=>'禁用',1=>'跳转真实地址',2=>'发送到浏览器'],
                    'relation'  => 'eq',
                    'title'     => '动态附件打开方式',
                ]),
                'op_module'   => 'admin',
                'op_controll' => 'upload',
                'op_action'   => 'index',
            ],
            [
                'op_name'     => 'attachment_score',
                'op_value'    => json_encode([
                    'type'         => 'number',
                    'value'        => 'intval',
                    'relation'     => 'eq',
                    'data-visible' => true,
                    'data-sortable'=> true,
                    'data-filter'  => false,
                ]),
                'op_module'   => 'attachment',
                'op_controll' => 'detail',
                'op_action'   => 'index',
                'op_order'    => 10,
            ]
        ]);
    }
    
    //批量添加后台菜单
    public function insertMenu()
    {
        //批量添加后台二级菜单
        $result = model('common/Menu','loglic')->install([
            [
                'term_name'   => '附件管理',
                'term_slug'   => 'attachment/admin/index',
                'term_info'   => 'fa-file',
                'term_module' => 'attachment',
            ],
        ],'系统');
        
        return true;
    }
    
    //卸载应用
    public function remove()
    {
        //删除公共配置(common)
        \daicuo\Op::delete_all([
            'op_module'   => 'common',
            'op_controll' => 'config',
            'op_name'     => 'attachment'
        ]);
        //删除表单扩展(admin)
        \daicuo\Op::delete_all([
            'op_autoload' => 'field',
            'op_module'   => 'admin',
            'op_controll' => 'upload',
            'op_name'     => 'attachment',
        ]);
        //删除插件配置表
        \daicuo\Op::delete_module('attachment');
        //删除插件队列表
        \daicuo\Term::delete_module('attachment');
        //返回结果
        return true;
    }
    
    //删除应用（配置、后台菜单）
    public function delete()
    {
        //删除内容数据
        \daicuo\Info::delete_all(['info_module'=>'attachment']);
        //删除基础数据
        $this->remove();
        //返回结果
        return true;
    }
}